package com.umanji.security.domain;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.IndexColumn;

import com.umanji.generic.entity.UUIDEntity;
import com.umanji.user.domain.Members;

@Entity
@Table(name="acl_object_identity")
public class AclObjectIdentity extends UUIDEntity<AclObjectIdentity> {

    @Column(name = "object_identity", unique = true, nullable = false)
    private String objectIdentity;

	@ManyToOne()
	@JoinColumn(name="parent_object", insertable=false, updatable=false, nullable=true)
    private AclObjectIdentity parentObject;

    // @OneToMany
    // @JoinColumn(name="acl_object_identity_id")
    // @OneToMany(mappedBy="acl_object_identity")
    // private List<AclPermission> aclPermissions;
	@OneToMany(mappedBy="aclObjectIdentity", cascade=CascadeType.ALL)
    private List<AclPermission> aclPermissions;

	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
	@Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
	@JoinColumn(name="parent_object", nullable=true)
	private List<AclObjectIdentity> children;

    private String aclClass;

	protected AclObjectIdentity() {
		// TODO Auto-generated constructor stub
	}

    public AclObjectIdentity(String object_identity, AclObjectIdentity parent_object, String acl_class) {
        this.objectIdentity = object_identity;
        this.parentObject = parent_object;
        this.aclClass = acl_class;
    }

    public AclObjectIdentity(String object_identity, String acl_class) {
        this.objectIdentity = object_identity;
        this.aclClass = acl_class;
    }

	public List<AclObjectIdentity> getChildren() {
	   return children;
	}

	public void setChildren(List<AclObjectIdentity> children) {
	   this.children = children;
	}
	
    public String getObjectIdentity() {
		return objectIdentity;
	}

    public void setObjectIdentity(String objectIdentity) {
    	objectIdentity = objectIdentity;
	}

    public AclObjectIdentity getParentObject() {
		return parentObject;
	}

    public void setParentObject(AclObjectIdentity parentObject) {
		this.parentObject = parentObject;
	}

    public String getAclClass() {
		return aclClass;
	}

    public void setAclClass(String aclClass) {
    	this.aclClass = aclClass;
	}

	public List<AclPermission> getAclPermissions() {
		return aclPermissions;
	}

	public void setAclPermissions(List<AclPermission> aclPermissions) {
		this.aclPermissions = aclPermissions;
	}

}
